package com.blackhorse.getStart;

import com.blackhorse.dao.UserDao;
import com.blackhorse.domain.User;
import com.blackhorse.mybatis.io.Resources;
import com.blackhorse.mybatis.sqlsession.SqlSession;
import com.blackhorse.mybatis.sqlsession.SqlSessionFactory;
import com.blackhorse.mybatis.sqlsession.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * 使用自定义mybatis框架执行查询所有
 */
public class CustomMyBatisTest {
    public static void main(String[] args) {
        InputStream is = Resources.getResourceAsStream("SqlMapConfig.xml");
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory sqlSessionFactory = builder.build(is);
        SqlSession sqlSession = sqlSessionFactory.openSession();

        UserDao dao = sqlSession.getMapper(UserDao.class);
        List<User> users = dao.findAll();
        for (User user : users) {
            System.out.println(user);

        }

        sqlSession.close();
    }
}
